package com.xiaobao.coalproperty.other.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.xiaobao.coalproperty.R;
import com.xiaobao.coalproperty.module.home.model.entity.GoodsDetailEntity;

import java.util.List;

public class PropertyAdapter extends RecyclerView.Adapter<PropertyAdapter.ViewHolder> {

    private Context mContext;
    private List<GoodsDetailEntity.DataBean.PeopleInfoBean> mAdapterData;

    public PropertyAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public List<GoodsDetailEntity.DataBean.PeopleInfoBean> getAdapterData() {
        return mAdapterData;
    }

    public void setAdapterData(List<GoodsDetailEntity.DataBean.PeopleInfoBean> mAdapterData) {
        this.mAdapterData = mAdapterData;
        this.notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_adapter_property, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tvName.setText(mAdapterData.get(position).getName());
        holder.tvCertificate.setText(mAdapterData.get(position).getCertificate_no());
        holder.tvNum.setText(mAdapterData.get(position).getNum());
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {
        if (mAdapterData == null) {
            return 0;
        }
        return mAdapterData.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvName, tvCertificate, tvNum;

        public ViewHolder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.property_name);
            tvCertificate = itemView.findViewById(R.id.property_certificate_no);
            tvNum = itemView.findViewById(R.id.property_num);
        }
    }


    //copy item
    private onItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(onItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    private View.OnClickListener itemOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClick(v, (Integer) v.getTag());
            }
        }
    };

    public interface onItemClickListener {
        void onItemClick(View view, int position);
    }
}
